package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.micro.TaxiGangCreator;

public class Promotion extends Composite {

	private static PromotionUiBinder uiBinder = GWT
	.create(PromotionUiBinder.class);

	interface PromotionUiBinder extends UiBinder<Widget, Promotion> {
	}


	private PopupPanel popupPanel = new DecoratedPopupPanel(false,true);

	@UiField
	Button continueButton;
//	@UiField
//	Button contestButton;
	@UiField
	Label alertText1;
	@UiField
	Label alertText2;
	@UiField
	Label alertText3;
	@UiField
	Label alertText4;
	@UiField
	Label alertText5;
	@UiField
	Label alertText6;
	@UiField
	Label alertText7;
	
	@UiField
	Image welcomeImage;

	

	public Promotion(final Command cmd,String title, String[] text, boolean showCancel,String width) {
		init(cmd,title, showCancel, width);
		if (text.length >0){
			alertText1.setText(text[0]);
		}
		if (text.length >1){
			alertText2.setText(text[1]);
		}
		if (text.length >2){
			alertText3.setText(text[2]);
		}
		if (text.length >3){
			alertText4.setText(text[3]);
		}
		if (text.length >4){
			alertText5.setText(text[4]);
		}
		if (text.length >5){
			alertText6.setText(text[5]);
		}
		if (text.length >6){
			alertText7.setText(text[6]);
		}
		String filler = "__________________________________________________________";
//		alertTextBlank1.setText(filler);
//		alertTextBlank2.setText(filler);
//		alertTextBlank3.setText(filler);
//		alertTextBlank4.setText(filler);
	}


	public void init(final Command cmd,String title, boolean showCancel,String width) {
		initWidget(uiBinder.createAndBindUi(this));
		//contestButton.setText("Ja, vielleicht");
		continueButton.setText("Weiter");

		popupPanel.setTitle("<p><b>"+title+"</b></p>");
		popupPanel.setWidth(width);
		//popupPanel.setWidth("422px");
		popupPanel.setGlassEnabled(true);
	    //		popupPanel.setHTML("<p><b>"+title+"</b></p>");

		popupPanel.center();
		welcomeImage.setUrl(MyResources.INSTANCE.promotion().getSafeUri());

		popupPanel.setWidget(this);

		continueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (cmd != null){
					cmd.execute();
				}
				popupPanel.hide();
			}
		});
		
//		contestButton.addClickHandler(new ClickHandler() {
//
//			@Override
//			public void onClick(ClickEvent event) {
//				Window.Location.assign("http://www.facebook.com/TaxigangBackstage/app_151941168272708"); 
//			}
//		});
		
        int left = (Window.getClientWidth()) / 3;
        int top = (Window.getClientHeight()) / 7;
        popupPanel.setPopupPosition(left, top);


	}


	public void show(){
		//popupPanel.center();

		popupPanel.show();
	}

}
